Repository navigation
Bug fix: H265 encoded images are incorrectly labelled - #800
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Although the one-line fix is correct and well-scoped, the author's own description identifies the same unread-parameter bug persisting in the stereo path (which does publish compressed output), so the fix is incomplete for that code path.
No open issues 🎉
What changed in this PR
This PR fixes a bug where H.265 (HEVC) encoded images were incorrectly labelled as libx264 in their FFMPEGPacket encoding field. The i_low_bandwidth_ffmpeg_encoder parameter was declared but never read, so ImgConverterConfig::ffmpegEncoder always fell back to its default (libx264). Downstream, ffmpeg_image_transport selects its decoder from this field, causing it to attempt an H.264 decoder on an HEVC stream. The one-line change wires the declared parameter into the converter config for the camera sensor node.
Changes:
- Read
ParamNames::LOW_BANDWIDTH_FFMPEG_ENCODERintoconvConfig.ffmpegEncoderinCamera::setupQueues, so the configured encoder label propagates throughImagePublishertoImageConverter::setFFMPEGEncoding().
| File | Description |
|---|---|
| depthai_ros_driver/src/dai_nodes/sensors/camera.cpp | Populates convConfig.ffmpegEncoder from the previously-unread i_low_bandwidth_ffmpeg_encoder param so FFMPEG packets carry the correct encoding label. |
I verified: the param constant exists (base_param_handler.hpp:16), it is declared for this node's handler (sensor_param_handler.cpp:36, with ph being a SensorParamHandler per camera.cpp:25), the target field ffmpegEncoder is a std::string (utils.hpp:57), and the value is consumed downstream (img_pub.cpp:101). The new line is consistent with the surrounding getParam calls. The default (libx264) preserves prior behavior, so H.264 output is unchanged. The remaining unread-param cases in stereo/thermal noted in the description are outside this diff and intentionally deferred.
Review effort: Balanced
The param was declared but never copied into ImgConverterConfig, so every FFMPEGPacket was labelled libx264, even for H.265 streams. ffmpeg_image_transport then picks an H.264 decoder for an HEVC bitstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0114oQMBcCFbwHvHoVjCKjmE
Stereo declares i_low_bandwidth_ffmpeg_encoder and the left/right rect variants, but setupStereoQueue and setupRectQueue never read them, so their FFMPEG packets were always labelled libx264. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QoDtVoMSv6LBPGZtf2pj33
81ae5cf to
94b0bef
Compare
|
Stereo is fixed too, in 94b0bef. Depth and the left/right rectified streams now read their |
Summary
i_low_bandwidth_ffmpeg_encoderis declared (defaultlibx264) but never read.ImgConverterConfig::ffmpegEncodertherefore always falls back to the default, andImagePublisherpasses that toImageConverter::setFFMPEGEncoding(). EveryFFMPEGPacketcomes out withencoding: libx264, even when the camera's VideoEncoder runsH265_MAIN.ffmpeg_image_transportpicks its decoder from that field, so it attempts to use an H.264 decoder for an HEVC stream.Known follow-ups, deliberately left out to keep this PR minimal:
The label and the encoder profile are still set independently. Profile
H265_MAINwith the encoder param left atlibx264still gives a wrong label, with no warning. A mismatch warning, or a profile-derived default, could be addedlater.
Same unread param in the other nodes.
stereo_param_handler.cppdeclaresi_low_bandwidth_ffmpeg_encoder,i_left_rect_low_bandwidth_ffmpeg_encoderandi_right_rect_low_bandwidth_ffmpeg_encoder, andthermal_param_handler.cppdeclaresi_low_bandwidth_ffmpeg_encoder. None of them is read instereo.cpp(setupStereoQueue,setupRectQueue) orthermal.cpp, so their FFMPEG packets are always labelledlibx264too.tof.cppsetsconvConfig.lowBandwidthbut the ToF param handler doesn't declare the param. Thermal and ToF don't publish compressed output today. Stereo does.Related issues
None
Compatibility and configuration
None. The param already exists, and its default (
libx264) matches the value thatwas previously hard-coded, so H.264 output is unchanged. Users who already set
i_low_bandwidth_ffmpeg_encoder(which had no effect before) now get that label.Repro config:
Testing
developbranchros2 run image_transport republish ffmpeg rawBuild. The same change on top of
v3.3.0-humblebuilds inros:humbleagainst the aptros-humble-depthai-ros-v33.3.0 packages, with no new warnings. This branch builds inros:kilted(depthai_ros_driver,depthai_bridge,depthai_ros_msgs,depthai_descriptionsfromdevelop, apt depthai-core 3.10.0).On a device. I built the one-line change on top of
v3.3.0-humble(no other changes) and ran it in a Humble container with the aptros-humble-depthai-ros-v33.3.0 packages, on both cameras at once. Each camera's FFMPEG stream was decoded withrepublish, and the packets and decoded images were recorded for 20 s:encodingH265_MAIN),i_low_bandwidth_ffmpeg_encoder: libx265;decoders.libx265:=hevclibx264h264_cuvid,h264, then segfaultslibx265hevcH264_HIGH), encoder param left at its default;decoders.libx264:=h264libx264h264Decoded images are 640x400
bgr8, in stamp order, with the packet'sframe_id. Every decoded frame inside the recording window carries the exact stamp of a published packet.Decoder side, without a device. Same
ffmpeg_image_transport3.0.5 andffmpeg_encoder_decoder3.0.1 as Humble apt. An rclpy node published 640x400 Annex-B packets (I/P only, keyframe every 30) shaped likeImageConverter::toRosFFMPEGPacketoutput: stamp, frame_id, pts in ns,flags = keyframe. They were decoded withros2 run image_transport republish ffmpeg raw:encodinglabellibx264(before)decoders.libx264:=hevcignoring invalid decoder hevc for codec libx264, picksh264_cuvid, segfaultlibx265(after)decoders.libx265:=hevclibx264(default)decoders.libx264:=h264Not tested on a device: this
developbranch on its own.AI
🤖 Generated with Claude Code & with a human too :)